// pages/worker/worker.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    btmType: 0, //底部tag选项值
    btmNavs: [
    //   {
    //   id: 1,
    //   name: '产业工人'
    // }, {
    //   id: 2,
    //   name: '建材家居'
    // }, {
    //   id: 3,
    //   name: '辅材品牌'
    // }, 
    {
      id: 0,
      name: '商品'
    },  {
      id: 4,
      name: '店铺'
    }],
    searchKey: '',
    list0: [],
    list1: [],
    list2: [],
    list3: [],
    list4: []
  },

  
  getList0(start = 0) {
    let that = this
    wx.$https('goods.list', {
      type: 0,
      searchKey: this.data.searchKey,
      start: start,
      limit: 10
    }).then(res => {
      that.setData({
        list0: start == 0 ? res : this.data.list0.concat(res)
      })
    })
  },


  // getList1(start = 0) {
  //   let that = this
  //   wx.$https('goods.list', {
  //     type: 1,
  //     searchKey: this.data.searchKey,
  //     start: start,
  //     limit: 10
  //   }).then(res => {
  //     that.setData({
  //       list1: start == 0 ? res : this.data.list1.concat(res)
  //     })
  //   })
  // },

  // getList2(start = 0) {
  //   let that = this
  //   wx.$https('project.list', {
  //     searchKey: this.data.searchKey,
  //     start: start,
  //     limit: 10
  //   }).then(res => {
  //     that.setData({
  //       list2: start == 0 ? res : this.data.list2.concat(res)
  //     })
  //   })
  // },

  // getList3(start = 0) {
  //   let that = this
  //   wx.$https('goods.list', {
  //     type: 2,
  //     searchKey: this.data.searchKey,
  //     start: start,
  //     limit: 10
  //   }).then(res => {
  //     that.setData({
  //       list3: start == 0 ? res : this.data.list3.concat(res)
  //     })
  //   })
  // },

  getList4(start = 0) {
    let that = this
    wx.$https('shop.list', {
      searchKey: this.data.searchKey,
      start: start,
      limit: 10
    }).then(res => {
      that.setData({
        list4: start == 0 ? res : this.data.list4.concat(res)
      })
    })
  },

  changeType: function (e) {
    let that = this;
    let type = e.currentTarget.dataset.type
    that.setData({
      btmType: type
    })
    this[`getList${type}`](0)
  },

  navWork(e) {
    let id = e.currentTarget.dataset.id
    wx.$nav('/pages/workerList/workerList', {
      id: id
    })
  },


  navDetail(e) {
    let goodsId = e.currentTarget.dataset.id
    wx.$nav('/pages/workerDetail/workerDetail', {
      goodsId: goodsId
    })
  },

  navShop(e) {
    let shopId = e.currentTarget.dataset.id
    wx.$nav('/pages/shop/shop', {
      shopId: shopId
    })
  },

  navShopDetail(e) {
    let goodsId = e.currentTarget.dataset.id
    wx.$nav('/pages/workerDetail/workerDetail', {
      goodsId: goodsId
    })
  },

  // navShop(e) {
  //   let id = e.currentTarget.dataset.id
  //   wx.$nav('/pages/bathroom/bathroom', {
  //     id: id
  //   })
  // },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      searchKey: options.searchKey
    })
    this[`getList${this.data.btmType}`](0)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let type = this.data.btmType
    this[`getList${type}`](this.data[`list${type}`].length)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})